home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 11.4 KB | 392 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Frame.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "IntlTest.hpp"
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef EDITVIEWS_H
- #include "EditViews.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWIDLE_H
- #include "FWIdle.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWSTATIC_H
- #include "FWStatic.h"
- #endif
-
- #ifndef FWTABBER_H
- #include "FWTabber.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfIntlTest
- #endif
-
- //========================================================================================
- // CIntlTestFrame class
- //========================================================================================
-
- FW_DEFINE_AUTO(CIntlTestFrame)
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame constructor
- //----------------------------------------------------------------------------------------
- CIntlTestFrame::CIntlTestFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CIntlTestPart* part) :
- FW_CFrame(ev, odFrame, presentation, part),
- FW_MDroppableFrame(ev, this),
- FW_MReceiver(),
- fTestPart(part),
- fTestView(NULL),
- fTestSelection((CIntlTestSelection*)presentation->GetSelection(ev)),
- fViewTabber(NULL)
- {
- FW_CIdler* idler = FW_NEW(FW_CIdler, (this, 15));
- idler->RegisterIdle(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame destructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestFrame::~CIntlTestFrame()
- {
- // fViewTabber is deleted automatically because it's an attached event handler
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CIntlTestFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
-
- // ----- Test for 'TEXT' also -----
- #ifdef FW_BUILD_MAC
- if (!acceptDrop)
- {
- for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0)) // 'TEXT' on Scrap
- return TRUE;
- }
- #endif
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CIntlTestFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CRect frameRect = GetBounds(ev);
- FW_CRect centerRect(GetFrame(ev)->GetContentView(ev)->GetBounds(ev));
-
- // Draw a gray background around the content view if it's smaller
- if (centerRect.right < frameRect.right || centerRect.bottom < frameRect.bottom ) {
-
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- // Draw outside the center view to avoid flashing
- FW_CAcquiredODShape aqPaneShape = ::FW_NewODShape(ev, frameRect);
- FW_CAcquiredODShape aqCenterShape = ::FW_NewODShape(ev, centerRect);
- aqPaneShape->Subtract(ev, aqCenterShape);
-
- FW_CRegionShape::RenderRegion(vc, aqPaneShape, FW_kFill, FW_kRGBLightGray);
-
- // Draw a shadow frame around the content view
- centerRect.Inset(-FW_IntToFixed(1),-FW_IntToFixed(1));
- FW_CRectShape::RenderRect(vc, centerRect, FW_kFrame);
- FW_CPoint p1(centerRect.left, centerRect.bottom);
- FW_CPoint p2(centerRect.right, centerRect.bottom);
- FW_CPoint p3(centerRect.right, centerRect.top);
- FW_CLineShape::RenderLine(vc, p1, p2);
- FW_CLineShape::RenderLine(vc, p2, p3);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CIntlTestFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- FW_CEditView* editView = NULL;
- ODID id = this->GetActiveEditViewId(ev);
- if (id)
- {
- editView = this->FindEditView(ev, id);
- }
-
- CIntlTestEditCommand* cmd = FW_NEW(CIntlTestEditCommand, (ev, commandID, this, fTestSelection, editView, FW_kCanUndo));
- return cmd;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CIntlTestFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- FW_CEditView* dropView = this->HitTest(ev, dropPoint);
- if (dropView)
- return FW_NEW(CIntlTestDropCommand, (ev, this, dropView, fTestSelection, dropInfo, odFacet, dropPoint));
-
- // dropPoint isn't in an edit view
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
- void CIntlTestFrame::CreateSubViews(Environment* ev)
- {
- FW_CFont helvetica(FW_kHelvetica, FW_kPlain, FW_IntToFixed(12));
-
- FW_CRect viewRect; // working rect for creating the views
- FW_CRect frameRect = GetBounds(ev);
- FW_CPoint extent;
- FW_CRect contentRect;
- GetContentRect(ev, contentRect, extent);
-
- // ----- Create the GrowBox only in root frame
- if (this->IsRoot(ev))
- {
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, contentRect.BotRight());
- }
- else
- {
- // Leave space to draw 1 pixel border in non-root frames
- frameRect.Inset(FW_kFixedPos1);
- }
-
- // ----- Create the content view
- CIntlTestView* contentView = new CIntlTestView(ev, this, contentRect, extent);
- contentView->MakeContentView(ev);
- fTestView = contentView;
-
- // ---- Create the static texts
- viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(10), FW_IntToFixed(150), FW_IntToFixed(30));
- FW_CStaticText* staticText1 = FW_NEW(FW_CStaticText, (ev, this, viewRect, FW_CString("Type here:")));
-
- viewRect.Set(FW_IntToFixed(160), FW_IntToFixed(10), FW_IntToFixed(300), FW_IntToFixed(30));
- FW_CStaticText* staticText2 = FW_NEW(FW_CStaticText, (ev, this, viewRect, FW_CString("ì¸óÕǵǃÇ≠ÇæÇ≥Ç¢ÅF"), gFontOsaka));
-
- // ----- Create the EditViews
- unsigned short attributes = FW_CEditView::kDrawBox + FW_CEditView::kAutoScroll;
- /* Set(L, T, R, B) */
-
- viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(40), FW_IntToFixed(150), FW_IntToFixed(60));
- CMyEditView* editView1 = FW_NEW(CMyEditView, (ev, contentView, kEnglishEditView, viewRect, helvetica, 32, attributes));
-
- viewRect.Set(FW_IntToFixed(160), FW_IntToFixed(40), FW_IntToFixed(300), FW_IntToFixed(60));
- CJapEditView* editView2 = FW_NEW(CJapEditView, (ev, contentView, kJapaneseEditView, viewRect, gFontOsaka, 32,
- attributes + FW_CEditView::kInlineInput + FW_CEditView::kTextServices));
- editView2->InitJapEditView(ev);
-
- attributes = FW_CEditView::kDrawBox + FW_CEditView::kWordWrap; // no autoscroll for this view
- viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(80), FW_IntToFixed(300), FW_IntToFixed(240));
- CMyEditView* editView3 = FW_NEW(CMyEditView, (ev, contentView, kTextEditView, viewRect, helvetica, 500, attributes));
-
- // ----- Tell edit views to notify the frame when something noteworthy occurs -----
- editView1->LinkToReceiver(this);
- editView2->LinkToReceiver(this);
- editView3->LinkToReceiver(this);
-
- // ----- Add a ViewTabber to the frame
- fViewTabber = new FW_CViewTabber(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- ODID CIntlTestFrame::GetActiveEditViewId(Environment* ev)
- {
- FW_MEventHandler* target = this->GetTarget(ev);
- if (target)
- {
- FW_CView* targetView = FW_DYNAMIC_CAST(FW_CView, target);
- if (targetView)
- return targetView->GetViewId(ev);
- }
-
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- FW_CEditView* CIntlTestFrame::FindEditView(Environment* ev, ODID id)
- {
- return (FW_CEditView*) fTestView->FindViewById(ev, id);
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
- {
- FW_CFrame::FacetAdded(ev, facet, facetCount); // Call inherited
-
- // Perform "DoPostCreate"-type initialization here.
- fTestPart->UpdateViewsFromTextData(ev);
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- // ---- Handle notification messages from the edit views
- if (notification.GetMessage() == kEditViewMsg)
- {
- fTestPart->Changed(ev); // so we can Save
- }
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestFrame::GetContentRect(Environment* ev, FW_CRect& rect, FW_CPoint& extent)
- {
- rect = GetBounds(ev);
-
- // Leave space to draw 1 pixel border in non-root frames
- if (IsRoot(ev) == FALSE)
- rect.Inset(FW_kFixedPos1);
-
- extent = rect.BotRight();
-
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
- rect.right -= sbSize.x;
- rect.bottom -= sbSize.y;
- }
-
- //----------------------------------------------------------------------------------------
- FW_CEditView* CIntlTestFrame::HitTest(Environment* ev, const FW_CPoint& where)
- {
- // Find out which edit view the point is in; return NULL if point is not in an edit view.
- FW_CEditView* editView;
- FW_CRect bounds;
-
- editView = this->FindEditView(ev, kTextEditView);
- bounds = editView->GetBounds(ev);
- if (bounds.Contains(where))
- return editView;
-
- editView = this->FindEditView(ev, kJapaneseEditView);
- bounds = editView->GetBounds(ev);
- if (bounds.Contains(where))
- return editView;
-
- editView = this->FindEditView(ev, kEnglishEditView);
- bounds = editView->GetBounds(ev);
- if (bounds.Contains(where))
- return editView;
-
- return NULL;
- }
-
-